<?php
class PresentationFileCategory extends Presentation {
    private static $categories;
    
    public function formatFormField(&$field) {
        parent::formatFormField($field);
        $field['type'] = 'select';
        $field['selected'] = $field['value'];
        $field['options'] = &$this->getFileCategoriesOptions();
    }
    
    private function &getFileCategoriesOptions($rootId = 0) {
        if (self::$categories) {
            return self::$categories;
        }
        $categories = &Modules::getModule('Files')->getCategoryContent($rootId);
        $options = array();
        foreach ($categories as &$category) {
            $options[$category['id']] = $category['name'];
            $subs = &$this->getFileCategoriesOptions($category['id']);
            foreach ($subs as $key => &$sub) {
                $options[$key] = "--$sub";
            }
        }
        if ($rootId == 0) {
            self::$categories = $options;
        }
        return $options;
    }
}